import matplotlib.pyplot as plt

def plot_and_save_trends(acc_list, f1_score_list, train_losses, test_losses, save_dir):
    # Plot and save recall trend
    plt.figure()
    plt.plot(range(1, len(acc_list) + 1), acc_list, label='Accuracy',color='black')
    plt.xlabel('Epoch')
    plt.ylabel('Accuracy')
    plt.title('Accuracy')
    plt.legend()
    plt.grid(False)
    plt.savefig(f'{save_dir}/Acc_plot{acc_list[0]}.png')

    # Plot and save F1-score trend
    # plt.figure()
    # plt.plot(range(1, len(f1_score_list) + 1), f1_score_list, label='F1-score')
    # plt.xlabel('Epoch')
    # plt.ylabel('F1-score')
    # plt.title('F1-score')
    # plt.legend()
    # plt.grid(False)
    # plt.savefig(f'{save_dir}/f1_score_plot{acc_list[0]}.png')
    plt.figure()
    plt.plot(range(1, len(f1_score_list) + 1), f1_score_list, label='F1-score', color='black')
    plt.xlabel('Epoch')
    plt.ylabel('F1-score')
    plt.title('F1-score')
    plt.legend()
    plt.grid(False)
    plt.savefig(f'{save_dir}/f1_score_plot{acc_list[0]}.png', bbox_inches='tight')

    # Plot and save training loss trend
    plt.figure()
    plt.plot(range(1, len(train_losses) + 1), train_losses, label='Loss',color='black')
    plt.xlabel('Epoch')
    plt.ylabel('Loss')
    plt.title('Loss')
    plt.legend()
    plt.grid(False)
    plt.savefig(f'{save_dir}/train_loss_plot{acc_list[0]}.png')
    print("训练损失已保存！")

    # Plot and save validation loss trend
    plt.figure()
    plt.plot(range(1, len(test_losses) + 1), test_losses, label='Loss',color='black')
    plt.xlabel('Epoch')
    plt.ylabel('Loss')
    plt.title('Loss')
    plt.legend()
    plt.grid(False)
    plt.savefig(f'{save_dir}/test_loss_plot{acc_list[0]}.png')
    print("验证损失已保存！")

# 使用示例
# recall_list = [0.5, 0.6, 0.7]
# f1_score_list = [0.55, 0.65, 0.75]
# train_losses = [0.8, 0.7, 0.6]
# valid_losses = [1.2, 1.1, 1.0]
# save_dir = 'huatu'
#
# plot_and_save_trends(recall_list, f1_score_list, train_losses, valid_losses, save_dir)